package com.lwq.lwqmicoservice.framework.service;

import com.lwq.lwqmicoservice.common.exception.FieldException;
import com.lwq.lwqmicoservice.common.model.Dto;
import com.lwq.lwqmicoservice.common.model.SysUser;
import com.lwq.lwqmicoservice.framework.mapper.UserMapper;
import com.lwq.lwqmicoservice.framework.mapper.UserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Description:
 * Author: LiuWenQing
 * Datetime: 2021/6/11
 */
@Service
public class UserService {

    @Autowired
    private UserMapper mapper;
    @Autowired
    private UserRoleMapper userRoleMapper;

    public SysUser getUser(Long userId){
        return mapper.selectById(userId);
    }

    public List<SysUser> list(Dto dto){
        return dto == null ? mapper.selectList(null) :
                mapper.selectByMap(dto);
    }

    public void update(SysUser user){
        if(user.getId() == null){
            throw new FieldException("id不可为空");
        }
        mapper.updateById(user);
    }

    public void delete(Long id){
        mapper.deleteById(id);
    }
}
